
## Figure 1 Map Leaders


library(MASS)
library(vegan)
library(foreign)
library(SnowballC)
library(rjags)
library(rworldmap)
library(RColorBrewer)
library(classInt)
library(dplyr)





leaders <- read.dta(file="output/leaders_map.dta")
# country labels to the map
sPDF <- joinCountryData2Map(leaders , joinCode = "ISO_N3", nameJoinColumn = "iso3n2", verbose=TRUE)




##Map % of leaders all times

out.file <- paste("output/leadersUN.pdf",sep="")
pdf(file=out.file, height=4, width=7)
par(mar=c(4,1,2,1))

#Setting up class intervals for continuous variable
classInt <- classIntervals(sPDF$leader2,
                           style="kmeans")

catMethod=classInt$brks

#Selecting diverging palette
colourPalette <- brewer.pal(9,"Greys")
#colourPalette <- brewer.pal(9,"PuOr")

#Drawing the map

mapParams <- mapCountryData(sPDF,nameColumnToPlot="leader2", 
                            #catMethod="pretty", 
                            catMethod=catMethod,
                            mapTitle="",
                            colourPalette=colourPalette,
                            #oceanCol="lightblue",
                            missingCountryCol="grey", 
                            addLegend="FALSE"
                            #borderCol="black"
)

#adding legend
do.call( addMapLegend, c( mapParams, legendLabels="all", 
                          labelFontSize=0.5,legendShrink=0.8,
                           legendWidth=0.5, legendIntervals="page"))
dev.off()  